<?php
namespace Home\Controller;
use Think\Controller;
// +----------------------------------------------------------------------
// | Date:2016年12月14日
// +----------------------------------------------------------------------
// | Author: EK_熊<1439527494@qq.com>
// +----------------------------------------------------------------------
// | Description: 此文件作用于****
// +----------------------------------------------------------------------
class PublicController extends Controller{
    
    
    
    public function login(){
        $jump = I('jumpurl') ? base64_decode(I('jumpurl')) : U('index/index');
        if (IS_POST){
            $accountService = D('Account','Service');
            $ret = $accountService->login(I('u_account'),I('u_password'));
            if (!$ret) $this->error($accountService->getError());
            $this->success('登录成功！',$jump);
            exit();
        }
        $this->assign('jumpurl',$jump);
        $this->display();
    }
    
    
    public function logout(){
        session('user',null);
        cookie('user',null);
        $this->success('退出成功！',U('index/index'));
    }
    
    /**
     * 分类列表，显示在首页和搜索页面
     * 
     * date:2016年12月20日
     * author: EK_熊
     */
    public function category(){
        $cat = new \Org\Util\Category(M('Category')->order('listorder asc'), array('cid', 'pid', 'name','name'));
        $cat_arr = $cat->getList();//获取分类结构
        $category= $cat->getTree2($cat_arr,0);
        $cat_tree = [];
        foreach($category as $k=>$v){
            $cat_tree[$v['code']] = $v;
        }
        $this->assign("cat_tree", $cat_tree);
    }
    
}